#include <QDebug>
#include <QDesktopWidget>
#include <QX11Info>
#include "dexwm.h"

/** \note
 *
 *	Requesting for \em SubstructureRedirectMask seems to prevent
 *	 Qt-based programs from painting themselves.
 *	 GTK-based programs are not affected by this.
 */

int DexXErrorHandler(Display *dsp, XErrorEvent *event)
	{
		Q_UNUSED(dsp);
		if (event->error_code == BadAccess)
		{
			qDebug() << "Another window manager is running. Now exiting...";
			exit(1);
		}
		return 0;
	}

int main(int argc, char *argv[])
	{
		DexWM a(argc, argv);

		// Check to see if another WM is running.
		XSetErrorHandler(DexXErrorHandler);
		XSelectInput(QX11Info::display(), QX11Info::appRootWindow(), SubstructureRedirectMask);
		a.syncX();

		XSelectInput(QX11Info::display(),
					 QApplication::desktop()->winId(),
					 SubstructureNotifyMask |
					 SubstructureRedirectMask |
					 StructureNotifyMask |
					 ButtonPressMask |
					 PropertyChangeMask |
					 KeyPressMask |
					 ColormapChangeMask |
					 EnterWindowMask);
		a.syncX();
		return a.exec();
	}
